<template>
  <div>
    <el-form :model="formInline" label-width="80px">
      <el-form-item label="用户名">
        <el-input v-model="formInline.UserName" placeholder="用户名" :disabled="true"></el-input>
      </el-form-item>
      <el-form-item label="真实名">
        <el-input v-model="formInline.RealName" placeholder="真实名" :disabled="true"></el-input>
      </el-form-item>
      <el-form-item label="邮箱">
        <el-input v-model="formInline.Email" placeholder="邮箱" :disabled="true"></el-input>
      </el-form-item>
      <el-form-item label="手机号">
        <el-input v-model="formInline.PhoneNum" placeholder="手机号" :disabled="true"></el-input>
      </el-form-item>

      <el-form-item label="类型">
        <el-select v-model="formInline.UserType" placeholder="类型" :disabled="true">
          <el-option label="一般用户" value="0"></el-option>
          <el-option label="会员用户" value="1"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="性别">
        <el-switch v-model="formInline.Sex" active-color="#13ce66" inactive-color="#ff4949" :disabled="true"></el-switch>
      </el-form-item>
      <el-form-item label="头像">
          <img v-if="formInline.PictureShow" :src="formInline.PictureShow" class="avatar" />
          <i v-else class="el-icon-plus avatar-uploader-icon"></i>
      </el-form-item>
      <el-form-item label="年龄">
        <el-input v-model="formInline.Age" placeholder="年龄" :disabled="true"></el-input>
      </el-form-item>
      <el-form-item class="viewdata_button">
        <el-button type="default" @click="ViewCancle">取消</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>
<script>
import {mixinDetailMixed} from '@/mixedObject/detailMixed';
export default {
  mixins:[mixinDetailMixed],
  props: ["currentId", "random"],
  data() {
    return {
     
    };
  },
  watch: {
    random(newValue, oldValue) {
      //初始化表单
      this.InitFormInLine();
    }
  },
  created() {
    //初始化表单
      this.InitFormInLine();
  },
  methods: {
    //初始化
    InitFormInLine() {
      this.$store
        .dispatch("user/GetUserInfoSingle", this.currentId)
        .then(data => {

          this.formInline = {
            Id:this.currentId,
            UserName: data.userName,
            RealName: data.realName,
            Email: data.email,
            PhoneNum: data.phoneNum,
            UserType:''+data.userType,
            Password: data.password,
            Sex: data.sex,
            PictureShow: "",
            Picture: data.picture,
            Age: data.age,
            TypeOper: "1"
          };

          if (data.picture) {
            let img = eval("(" + data.picture + ")");
            this.formInline.PictureShow =this.baseUrl + img.fileUrls;
          }
        });
    },
    //图片上传成功
    handleAvatarSuccess(res, file) {
      this.formInline.PictureShow = URL.createObjectURL(file.raw);
      this.formInline.Picture = JSON.stringify(res.data);
    },
    //上传图片验证
    beforeAvatarUpload(file) {
      const isJPG = file.type === "image/jpeg";
      const isLt2M = file.size / 1024 / 1024 < 2;

      if (!isJPG) {
        this.$message.error("上传头像图片只能是 JPG 格式!");
      }
      if (!isLt2M) {
        this.$message.error("上传头像图片大小不能超过 2MB!");
      }
      return isJPG && isLt2M;
    },
   
  }
};
</script>
<style lang="scss" scoped>
.avatar-uploader .el-upload {
  border: 1px dashed #d9d9d9;
  border-radius: 6px;
  cursor: pointer;
  position: relative;
  overflow: hidden;
}
.avatar-uploader .el-upload:hover {
  border-color: #409eff;
}
.avatar-uploader-icon {
  font-size: 28px;
  color: #8c939d;
  width: 178px;
  height: 178px;
  line-height: 178px;
  text-align: center;
}
.avatar {
  width: 178px;
  height: 178px;
  display: block;
}
</style>